﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Libraries.Entities;
using Libraries.Repositories;

namespace Libraries
{
    public class TrainingManagerSystemModel : ITrainingManagerSystemModel
    {
        private CourseRepository _courseRepository;
        private CourseCategoryRepository _courseCategoryRepository;
        private CourseInstructorRepository _courseInstructorRepository;
        private CourseFeedBackRepository _courseFeedBackRepository;
        private CourseInformationEmployeeRepository _courseInformationEmployeeRepository;
        #region Account-Course
        private AccountCourseRepository _repository;
        private LanguageScoreRepository _languageScoreRepository;
        private LanguageTypeRepository _languageTypeRepository;
        private DepartmentRepository _departmentRepository;
        private StatusAccountRepository _statusAccountRepository;

        public Collection<AccountCourse> PagingAccountCourse(int pageSize, int pageNumber,
                                                             string accountName, string employeeId, int courseCategoryId,
                                                             string courseName, string fullName,
                                                             string endDateFrom, string endDateTo,
                                                             int accountLocation, int accountStatus,
                                                             int contractType, string roleId, string courseYear, int maxMonth,
                                                             int minMonth, int departmentId)
        {
            _repository = new AccountCourseRepository();
            return _repository.PagingAccountCourse(pageSize, pageNumber, accountName,
                                                  employeeId, courseCategoryId, courseName, fullName, endDateFrom,
                                                  endDateTo, accountLocation, accountStatus, contractType, roleId,
                                                  courseYear, maxMonth, minMonth, departmentId);
        }

        public Collection<CourseRefund> AccountCourseRefund(string employeeId)
        {
            _accountRepository = new AccountRepository();
            return _accountRepository.AccountCourseRefund(employeeId);
        }

        public Collection<CertificateRefund> AccountCertificateRefund(string employeeId)
        {
            _accountRepository = new AccountRepository();
            return _accountRepository.AccountCertificateRefund(employeeId);
        }


        #endregion

        #region Account-Certificate

        private AccountCertificateRepository _accountCertificateRepository;
        public Collection<AccountCertificate> SearchAccountCertificate(int pageSize, int currentPage, int certificateId, string employeeId, string certificateProvider, string certificateCategory, string accountName, string certificateName, string score, bool isCertificateNode, int statusAccountId)
        {
            _accountCertificateRepository = new AccountCertificateRepository();
            return _accountCertificateRepository.Search(pageSize, currentPage, certificateId, employeeId, certificateProvider, certificateCategory, accountName, certificateName, score, isCertificateNode, statusAccountId);
        }

        public Collection<Certificate> Certificates()
        {
            _accountCertificateRepository = new AccountCertificateRepository();
            return _accountCertificateRepository.Certificates();
        }

        public Certificate CertificateDetailByCertificateId(int certificateId) {
            _accountCertificateRepository=new AccountCertificateRepository();
            return _accountCertificateRepository.CertificateDetailByCertificateId(certificateId);
        }

        #endregion

        #region LanguageScore
        public Collection<LanguageScore> PagingLanguageScore(int pageSize, int currentPage, string accountName,
                                                             string fullName, int? languageTypeId, string score,
                                                                int departmentId, int statusAccountId, bool final)
        {
            _languageScoreRepository = new LanguageScoreRepository();
            return _languageScoreRepository.SearchLanguageScorePaging(pageSize, currentPage, accountName, fullName,
                                                                      languageTypeId, score, departmentId,
                                                                      statusAccountId, final);
        }

        public Collection<LanguageScore> LanguageScoresHistory(string accountName)
        {
            _languageScoreRepository = new LanguageScoreRepository();
            return _languageScoreRepository.ListLanguageScoresHistory(accountName);
        }

        public Collection<LanguageScore> ListLanguageScoreByLanguageType(int pageSize, int currentPage, int? languageTypeId)
        {
            _languageScoreRepository = new LanguageScoreRepository();
            return _languageScoreRepository.ListLanguageScoreByLanguageType(pageSize, currentPage, languageTypeId);
        }

        public LanguageScore GetLanguageScoreDetailById(int languageScoreId)
        {
            _languageScoreRepository = new LanguageScoreRepository();
            return _languageScoreRepository.GetLanguageScoreDetailById(languageScoreId);
        }

        public Collection<LanguageScore> HistoryLanguageScoreByTypeAndEmployeeId(int languageType, string employeeId) {
            _languageScoreRepository=new LanguageScoreRepository();
            return _languageScoreRepository.HistoryLanguageScoreByTypeAndEmployeeId(languageType, employeeId);
        }

        #endregion

        #region LanguageType
        public Collection<LanguageType> ListAllLanguageType()
        {
            _languageTypeRepository = new LanguageTypeRepository();
            return _languageTypeRepository.ListAllLanguageType();
        }
        #endregion

        #region Department
        public Collection<Department> ListAllDepartment(int locationId)
        {
            _departmentRepository = new DepartmentRepository();
            return _departmentRepository.ListAllDepartment(locationId);
        }
		public Collection<Department> ListAllDepartmentPaging(int pageSize, int currentPage,int locationId)
        {
            _departmentRepository = new DepartmentRepository();
            return _departmentRepository.ListAllDepartmentPaging(pageSize,currentPage,locationId);
        }
        #endregion

        #region StatusAccount
        public Collection<StatusAccount> ListAllStatusAccount()
        {
            _statusAccountRepository = new StatusAccountRepository();
            return _statusAccountRepository.ListAllStatusAccount();
        }
        #endregion

        #region Account

        private AccountRepository _accountRepository;
        public ICollection<Account> PagingAccount(string accountName, string fullName,
                                                    int? locationId, int? jobTitleId, string employeeId, int? departmentId,
                                                    int? contractTypeId, int? statusAccountId, int minMonth, int maxMonth,
                                                    int pageNumber, int pageSize)
        {
            _accountRepository = new AccountRepository();
            return _accountRepository.PagingAccount(accountName, fullName,
                                            locationId, jobTitleId, employeeId, departmentId,
                                            contractTypeId, statusAccountId, minMonth, maxMonth,
                                            pageNumber, pageSize);
        }

        public Account GetAccountByEmployeeId(string employeeId)
        {
            _accountRepository = new AccountRepository();
            return _accountRepository.GetAccountDetailsById(employeeId);
        }

        public ICollection<JobTitle> FetchAllJobTitle()
        {
            _accountRepository = new AccountRepository();
            return _accountRepository.FetchAllJobTitle();
        }

        public ICollection<ContractType> FetchAllContractType()
        {
            _accountRepository = new AccountRepository();
            return _accountRepository.FetchAllContractType();
        }

        public ICollection<Location> FetchAllLocation()
        {
            _accountRepository = new AccountRepository();
            return _accountRepository.FetchAllLocation();
        }


        #endregion

        #region Article
        ///// <summary>
        ///// Gets the article paging.
        ///// </summary>
        ///// <param name="pageSize">Size of the page.</param>
        ///// <param name="pageNumber">The page number.</param>
        ///// <param name="TotalRecords">The total records.</param>
        ///// <returns></returns>
        //public Collection<Article> GetArticlePaging(int pageSize, int pageNumber, out int TotalRecords) {
        //    //return new ArticleRepository().GetArticlePaging(pageSize, pageNumber, out TotalRecords);
        //    return new Collection<Article>();
        //}
        /// <summary>
        /// Gets the article paging.
        /// </summary>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="TotalRecords">The total records.</param>
        /// <returns></returns>
        public Collection<Article> GetArticlePaging(int pageSize, int pageNumber, out int TotalRecords)
        {
            return new ArticleRepository().GetArticlePaging(pageSize, pageNumber, out TotalRecords);
        }

        /// <summary>
        /// Gets the article by id.
        /// </summary>
        /// <param name="articleId">The article id.</param>
        /// <returns></returns>
        public Article GetArticleById(int articleId)
        {
            //return new ArticleRepository().GetArticleById(articleId);
            return new Article();
        }

        ///// <summary>
        ///// Updates the article.
        ///// </summary>
        ///// <param name="article">The article.</param>
        ///// <returns></returns>
        //public bool UpdateArticle(Article article) {
        //    //return new ArticleRepository().UpdateArticle(article);
        //    return true;
        //}
        /// <summary>
        /// Updates the article.
        /// </summary>
        /// <param name="article">The article.</param>
        /// <returns></returns>
        public bool UpdateArticle(Article article)
        {
            return new ArticleRepository().UpdateArticle(article);
        }


        //public Collection<CourseInstructor> FetchAllByInstructorId(string instructorId)
        //{
        //    return new CourseInstructorRepository().FetchAllByInstructorId(instructorId);
        //}


        #endregion

        #region Course
        /// <summary>
        /// Paging all course
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="currentpage"></param>
        /// <returns></returns>
        public Collection<CourseDetails> PagingAllCourse(int pagesize, int currentpage)
        {
            _courseRepository = new CourseRepository();
            return _courseRepository.PagingAllCourse(pagesize, currentpage);
        }

        public Collection<CourseDetails> PagingAllCourseByCategoryId(int pagesize, int currentpage, int categoryId)
        {
            _courseRepository = new CourseRepository();
            return _courseRepository.PagingAllCourseByCategoryId(pagesize, currentpage, categoryId);
        }
        /// <summary>
        /// Search course by courseName, CouserYear, start date and end date with paging
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="currentpage"></param>
        /// <param name="categoryId"></param>
        /// <param name="courseName"></param>
        /// <param name="courseYear"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        public Collection<CourseDetails> PagingSearchCourseByCategoryId(int pagesize, int currentpage, int categoryId, string courseName, int? courseYear, string startDate, string endDate)
        {
            _courseRepository = new CourseRepository();
            
            return _courseRepository.PagingSearchCourseByCategoryId(pagesize, currentpage, categoryId, courseName, courseYear, startDate, endDate);
            
        }

        /// <summary>
        /// Search Course by courseCategoryName with paging
        /// </summary>
        /// <param name="courseCategoryName"></param>
        /// <returns></returns>
        public Collection<CourseCategory> CourseCategorySearchPaging(string courseCategoryName)
        {
            _courseCategoryRepository = new CourseCategoryRepository();
            return _courseCategoryRepository.CourseCategorySearchPaging(courseCategoryName);
        }

        /// <summary>
        /// All course
        /// </summary>
        /// <returns></returns>
        public Collection<CourseCategory> CourseCategoryFetchAllName()
        {
            _courseCategoryRepository = new CourseCategoryRepository();
            return _courseCategoryRepository.CourseCategoryFetchAllName();
        }
        /// <summary>
        /// All instructor for course by courseId
        /// </summary>
        /// <param name="courseId"></param>
        /// <returns></returns>
        public Collection<CourseInstructor> AllCourseInstructorByCourseId(int courseId)
        {
            _courseInstructorRepository = new CourseInstructorRepository();
            return _courseInstructorRepository.CourseInstructorsByCourseId(courseId);
        }

        /// <summary>
        /// All feedback course by courseId
        /// </summary>
        /// <param name="courseId"></param>
        /// <returns></returns>
        public Collection<CourseFeedBack> AllCourseFeedBackByCourseId(int courseId)
        {
            _courseFeedBackRepository = new CourseFeedBackRepository();
            return _courseFeedBackRepository.CourseFeedBacks(courseId);
        }
        /// <summary>
        /// All employee follow course by courseId
        /// </summary>
        /// <param name="courseId"></param>
        /// <returns></returns>
        public Collection<CourseInfomation> AllEmployeeInformationByCourseId(int courseId)
        {

            _courseInformationEmployeeRepository = new CourseInformationEmployeeRepository();
            return _courseInformationEmployeeRepository.AllEmployeeByCourseId(courseId);
        }

        /// <summary>
        /// Details course by courseId
        /// </summary>
        /// <param name="courseId"></param>
        /// <returns></returns>
        public CourseDetails CourseDetailsByCourseId(int courseId)
        {
            _courseRepository = new CourseRepository();
            return _courseRepository.GetCourseDetailsById(courseId);
        }
        #endregion

        #region CheckRole

        private RolePermissionRepository _rolePermissionRepository;
        public bool CheckRole(string accountName, string function)
        {
            _rolePermissionRepository = new RolePermissionRepository();
            return _rolePermissionRepository.CheckRole(accountName, function);
        }

        public Collection<CourseInstructor> FetchAllByInstructorId(string instructorId) {
            CourseInstructorRepository _courseInstructorRepository=new CourseInstructorRepository();
            return _courseInstructorRepository.FetchAllByInstructorId(instructorId);
        }

        #endregion
    }
}
